
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

class PersonSortable2 implements Comparable<PersonSortable2>{
	private String name ;
	private int age ;
	public PersonSortable2(String name, int age) {
		this.name = name;
		this.age = age;
	}
	
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}
	public int getAge() {
		return age;
	}

	public void setAge(int age) {
		this.age = age;
	}

	public String toString() {
		return this.name + "-" + this.age ;
	}

	public int compareTo(PersonSortable2 o) {
		if(this.name.equals(o.name))
			return this.age - o.age ;
		return this.name.compareTo(o.name);
	}

}
class NameComparator implements Comparator<PersonSortable2>{
	public int compare(PersonSortable2 person1, PersonSortable2 person2){
		return person1.getName().compareTo(person2.getName()) ;
	}
}
class AgeComparator implements Comparator<PersonSortable2>{
	public int compare(PersonSortable2 person1, PersonSortable2 person2){
		return person1.getAge() - person2.getAge() ;
	}
}
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		PersonSortable2 persons[] = new PersonSortable2[n];
		for(int i = 0; i < n ; i++){
			persons[i] = new PersonSortable2(sc.next(),sc.nextInt());
		}
		System.out.println("NameComparator:sort");
		Arrays.sort(persons,new NameComparator());
		for (int i = 0; i < persons.length; i++) {
			System.out.println(persons[i]);
		}
		System.out.println("AgeComparator:sort");
		Arrays.sort(persons,new AgeComparator());
		for (int i = 0; i < persons.length; i++) {
			System.out.println(persons[i]);
		}
		System.out.println(Arrays.toString(NameComparator.class.getInterfaces()));
		System.out.println(Arrays.toString(AgeComparator.class.getInterfaces()));
	}
	
}
